<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<div style="width: 10px;height: 30px"></div>
<form class="layui-form" style="width: 80%;">
    <input type="hidden" name="adminId" th:value="${admin.adminId}">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" id="password" class="layui-input"
                       lay-verify="required" name="password"  placeholder="请输入旧密码">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPwd" class="layui-input"
                       lay-verify="newPwd" placeholder="请输入新密码">
            </div>
        </div>
    <div class="layui-form-item">
        <label class="layui-form-label">重复密码</label>
        <div class="layui-input-block">
            <input type="password" name="reNewPwd" class="layui-input"
                   lay-verify="reNewPwd" placeholder="请输入新密码">
        </div>
    </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="updPwd" lay-submit="" lay-filter="updPwd">修改密码</button>
            </div>
        </div>
</form>



<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['form','laydate','layer','jquery'],function () {
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.jquery;
        laydate.render({
            elem:'#birthday',
            max:'new Date()',
            trigger:'click'
        })
        form.verify({
            password: [/(.+){3,8}$/, '密码必须3到8位'],
            newPwd:[/(.+){3,8}$/, '密码必须3到8位'],
            reNewPwd:function () {
                var reNewPwd = $('reNewPwd').val();
                var newPwd = $('newPwd').val();
                if (newPwd != reNewPwd){
                    return '两次输入密码不一致';
                }
            }
        })
        //修改
        form.on('submit(updPwd)',function (data) {
            $.ajax({
                url:'/admin/updPwd',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('修改成功',{icon:1},function () {
                            $.ajax({
                                url:'/logout'
                            })
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })

    })
</script>
</body>
</html>